package com.itheima.case2.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class TimeAdvice {

    //service包下的所有find开头的方法为切入点
    @Pointcut("execution(* com.itheima.case2.service..*.find*(..))")
    public void pt(){

    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp){
        Object result = null;
        try {
            long startTime = System.currentTimeMillis();
            result = pjp.proceed();
            long endTime = System.currentTimeMillis();

            String name = pjp.getSignature().getName();
            System.err.println(name + "运行耗时:" + (endTime - startTime));
        } catch (Throwable throwable) {

        }
        return result;
    }

}
